/// Creator:      gaoruishan
/// CreatDate:    2025-07-29
/// Description:  护理计划
Class Nur.MNISV3.Service.NursingPlan Extends %RegisteredObject [ Not ProcedureBlock ]
{

/// 获取护理问题列表
/// w ##class(Nur.MNISV3.Service.NursingPlan).GetQuestionDataV4("","2025-07-31","2025-07-31","3","20665","8","2","23","","{""single"":"""",""multiple"":""1""}")
ClassMethod GetQuestionDataV4(episodeId, fromDate, toDate, wardId, userId, locId, hospitalId, groupId, screenParts, extras) As %String
{
    n (episodeId, fromDate, toDate, wardId, userId, locId, hospitalId,groupId,screenParts, extras,%session)
    s $zt="errGetQuestionDataV4"
    s ^GRS("GetQuestionDataV4",episodeId_"-")=$lb(episodeId, fromDate, toDate, wardId, userId, locId, hospitalId,groupId,screenParts, extras)
    s Msg="成功",msgcode="999999",Status="0" //定义初始值
    s json=##class(%ArrayOfDataTypes).%New()
    
    s NurPlanComConfig=##class(Nur.NIS.Service.NursingPlan.NursePlanMake).GetNurPlanCommonConfigGlobal(hospitalId)
    s ^GRS("NurPlanComConfig")=NurPlanComConfig
    s ServerObj=##class(Nur.MNISV3.Common.JSON).Decode(NurPlanComConfig)
    ;;;目标达成天数需要在前端控制，不能提前组织的配置原封不动的返回
    s config=##class(%ArrayOfDataTypes).%New()
    d config.SetAt(ServerObj.GetAt("QPCCOpenPlayDays"),"QPCCOpenPlayDays")
    d config.SetAt(ServerObj.GetAt("QPCCDefaultPlayDays"),"QPCCDefaultPlayDays")
    ;;;停止原因、作废原因、评价结果下拉框选项原封不动的返回
    s QSStopReasonJson=##class(Nur.MNISV3.Common.JSON).Decode(ServerObj.GetAt("QSStopReasonJson"))
    s UnUseReasonJson=##class(Nur.MNISV3.Common.JSON).Decode(ServerObj.GetAt("UnUseReasonJson"))
    s QuestionEvaluateResultJson=##class(Nur.MNISV3.Common.JSON).Decode(ServerObj.GetAt("QuestionEvaluateResultJson"))
    s QPCCTransReasonJson=##class(Nur.MNISV3.Common.JSON).Decode(ServerObj.GetAt("QPCCTransReasonJson"))
    d config.SetAt(QSStopReasonJson,"QSStopReasonJson")
    d config.SetAt(UnUseReasonJson,"UnUseReasonJson")
    d config.SetAt(QuestionEvaluateResultJson,"QuestionEvaluateResultJson")
    d config.SetAt(QPCCTransReasonJson,"QPCCTransReasonJson")
    ;;;设置button，底部只显示评价，侧滑显示复制、作废、撤销作废等
    s slide=##class(%ArrayOfDataTypes).%New()
    s buttons=##class(%ListOfDataTypes).%New()
    d buttons.Insert(##class(Nur.Tools).RapidAssembly("id,text,motion","CopyQuestion","复制","copy"))
    ;;;是否启用护理评价
    i (ServerObj.GetAt("IsOpenNurEvaluate")="Y")||(ServerObj.GetAt("StopApplyToQuestion")="Y")  { 
        d buttons.Insert(##class(Nur.Tools).RapidAssembly("id,text,motion","QuestionStop","停止","stop"))
    }
    i (ServerObj.GetAt("UnUserApplyToQuestion")="Y") {
        d buttons.Insert(##class(Nur.Tools).RapidAssembly("id,text,motion,backgroundColor","QuestionUnUse","作废","unuse","#FF0000"))
    }
    d slide.SetAt(buttons,"buttons")
    
    s screenPartsList=##class(%ListOfDataTypes).%New()
    s part1=..AddScreenPartObject("true","qStatus","状态","Single","未停止!已停止!已撤销!已作废")
    d screenPartsList.Insert(part1)
    s part1=..AddScreenPartObject("true","eStatus","评价状态","Single","未评价!已评价")
    d screenPartsList.Insert(part1)
    s part1=..AddScreenPartObject("true","source","来源","Single","评估带入!手动添加!数值带入!复制!医嘱带入!诊断带入")
    d screenPartsList.Insert(part1)
    
    s patInfoList=##class(%ListOfDataTypes).%New()  
    i episodeId'="" {//单患者
        s patinfo=##class(%ArrayOfDataTypes).%New()
        //基本患者信息
        s patinfo=##class(Nur.MNISV3.Service.Patient).GetBasicInfo(patinfo,episodeId)
        s questionData=..GetQuestionDataObj(episodeId,fromDate,toDate, wardId, userId, locId, hospitalId,groupId,screenParts) 
        d patinfo.SetAt($g(questionData),"questionData")
        d patInfoList.Insert(patinfo)
    }else {
        //调用纯净版患者列表，
        s patListObj=##class(%ResultSet).%New("Nur.MNISV3.Service.Patient:GetPatList")
        d patListObj.Execute(wardId,userId,"Ward",locId)
        while(patListObj.Next()){
            s patinfo=##class(Nur.MNISV3.Common.Utils).ResultSet(patListObj)
            s episodeId=patListObj.GetDataByName("episodeId")
            s questionData=..GetQuestionDataObj(episodeId,fromDate,toDate, wardId, userId, locId, hospitalId,groupId,screenParts) 
            d patinfo.SetAt($g(questionData),"questionData")
            //基本患者信息
            s patinfo=##class(Nur.MNISV3.Service.Patient).GetBasicInfo(patinfo,episodeId)
            d patInfoList.Insert(patinfo)
        }
    }
    d json.SetAt($g(Msg),"msg")
    d json.SetAt($g(msgcode),"msgcode")
    d json.SetAt($g(Status),"status")
    d json.SetAt($g(patInfoList),"patients")
    d json.SetAt(config,"NurPlanComConfig")
    d json.SetAt($g(slide),"slide")
    d json.SetAt($g(screenPartsList),"screenParts")
    d json.SetAt($g(buttons),"buttons")
    q ##class(Nur.MNISV3.Common.JSON).Encode(json)
errGetQuestionDataV4
    s Msg=$ze
    q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson(Msg,"100021","-1")
}

/// 编辑护理问题（修改状态、天数等）
/// w ##class(Nur.MNISV3.Service.NursingPlan).EditQuestionV4("","471","execute","{""date"":""2025-07-24"",""subjectIds"":[""85""],""contents"":[{""pid"":""0"",""eduContent"":""手腕带宣教"",""subjectId"":""85"",""taskId"":""""},{""pid"":""85"",""eduContent"":""亲爱的病友\n    在您办理入院手续后我们为您打印腕带，内容包含您的姓名，住院号，性别及年龄等等，护士将双人核对您腕带上的内容，核对无误后将为您佩戴腕带\n护士将根据您的生活习惯，疾病及局部皮肤血运等情况选择佩戴肢体\n住院期间均须佩戴腕带，请在行各种检查及治疗护理时配合医护人员出示腕带\n如腕带上的信息模糊或者腕带损坏，请告知护士给予重新打印并为您佩戴如佩戴腕带时自觉局部皮肤红痒或其他不适时应及时告知医护人员\n出院时护士会为您去除腕带\n谢谢您的配合"",""subjectId"":"""",""taskId"":""""}],""options"":[{""id"":""1"",""option"":""本人""},{""id"":""2"",""option"":""小学""},{""id"":""3"",""option"":""书写、印刷""},{""id"":""4"",""option"":""我已完全了解""},{""id"":""5"",""option"":""完全了解""}],""time"":""15:21"",""taskIds"":""[]"",""remarks"":""""}","3","20665","8","2","23")
ClassMethod EditQuestionV4(id, episodeId, motion, form, wardId, userId, locId, hospitalId, groupId) As %String
{
    n (id,episodeId,motion,form,wardId, userId, locId, hospitalId,groupId,%session)
    s $zt="errEditQuestionV4"
    s ^GRS("EditQuestionV4",episodeId_"-")=$lb(id,episodeId,motion,form,wardId, userId, locId, hospitalId,groupId)
    s Msg="成功",msgcode="999999",Status="0" //定义初始值
    s json=##class(%ArrayOfDataTypes).%New()
    s formObj=##class(Nur.MNISV3.Common.JSON).Decode(form)
    ;;;有参数都是要弹框的，无参就是不弹
    i ($g(episodeId)="")&&($g(id)'="") s episodeId=..GetAdmIdByPlanId(id)
    i (motion="indate") { //目标天数  indate传days；天数取数字
        s days=formObj.GetAt("days")
        s output=##class(Nur.NIS.Service.NursingPlan.QuestionRecord).SavePalyDays(id,days )
        i output'=0 s Status="-1",Msg=output
    } 
    if (motion="evaluate") {//评价 evaluate传result；
        s result=formObj.GetAt("result")
        s quesSub=$p(id,"||",2)
        s output=##class(Nur.NIS.Service.NursingPlan.GoalInterventionRecord).SaveQuestionComments(episodeId,quesSub,result,userId)
        i (output'=0) {
            s Status="-1",Msg=output
       }else  {
            s NurPlanComConfigExtJson=##class(CF.NUR.NIS.QPCommonConfigExt).GetQPCCEDataJSON(hospitalId)
            s NurPlanComConfigExt=##class(Nur.MNISV3.Common.JSON).Decode(NurPlanComConfigExtJson)
            f ind=1:1:NurPlanComConfigExt.Count(){
                s NurPlanObj=NurPlanComConfigExt.GetAt(ind)
                i (NurPlanObj.GetAt("QPCCEDescription")=result)&&(NurPlanObj.GetAt("QPCCEOpenCopyQuestion")="Y") {
                    s quesItemId=..GetQuestionIdByPlanId(id)
                    s name=..GetQuestionName(quesItemId)
                    s message="'"_name_"' 护理问题评价结果为 '"_result_"' ,是否复制该护理问题?"
                    ;;;如果未复制问题，填写转归原因
                    s outcome=$s(NurPlanObj.GetAt("QPCCEOpenFillOutcome")="Y":"outcome", 1:"")
                    s dialog=..CreateDialog("提示",message,"确定","copy","取消",outcome)
                }
            }
        }
    } 
    if (motion="unuse") { // 作废
        s type=formObj.GetAt("type") ;;;问题，目标，措施
        s reason=formObj.GetAt("reason") ;;;这两个方法最后两个参数™是反的
        i ($g(type)="goal") {
            s planId=$p(id,"||")
            s questSub=$p(id,"||",2)
            s intRecordIDs=formObj.GetAt("intRecordIds")
            s ret= ##class(Nur.NIS.Service.NursingPlan.GoalInterventionRecord).UnUseGoalRecord(userId,planId,questSub,intRecordIDs,reason)
        }elseif($g(type)="interv"){
            s intRecordIDs=formObj.GetAt("intRecordIds")
            s ret=##class("Nur.NIS.Service.NursingPlan.GoalInterventionRecord").CancelInterventions(userId,intRecordIDs,reason)
        }else {
            s ret=##class(Nur.NIS.Service.NursingPlan.QuestionRecord).AbolishQuestion(episodeId,userId,id,reason)
        }
        i (ret'=0) s Status="-1",Msg=ret
    }
    if (motion="copy") { // 复制
        s quesItemId=formObj.GetAt("questionId") ;;;当前左滑操作行的问题
        s ret=##class(Nur.NIS.Service.NursingPlan.QuestionRecord).CopyQuestionRecord(episodeId,wardId,userId,quesItemId)
        i (ret'=0)  s Status="-1",Msg=ret
    } 
    if (motion="stop") { // 停止
        s reason=formObj.GetAt("reason")
        s ret=##class(Nur.NIS.Service.NursingPlan.QuestionRecord).StopQuestion(episodeId,userId,reason,id)
        i (ret'=0) s Status="-1",Msg=ret
    } 
    if (motion="delete"){ // 删除
        s type=formObj.GetAt("type") 
        i ($g(type)="goal") {
            s goalId=formObj.GetAt("intRecordIds")
            s ret=##class(Nur.NIS.Service.NursingPlan.GoalInterventionRecord).delGoalRecordManual(goalId)
        }elseif($g(type)="interv"){
            s questionDR=$p(id,"||",2)
            s interventionDR=formObj.GetAt("intRecordIds")
            s ret=##class("Nur.NIS.Service.NursingPlan.GoalInterventionRecord").DeleteNewInterventions(userId,episodeId,questionDR,interventionDR,"")
        }
        i (ret'=0) s Status="-1",Msg=ret
    }
    i (motion="save") { // 新增一个问题
        s quesItemId=formObj.GetAt("questionId")
        s ret=##class(Nur.NIS.Service.NursingPlan.QuestionRecord).SaveNewQuestionRecord( episodeId,wardId,userId,quesItemId)
        i (ret'=0) s Status="-1",Msg=ret
    }
    d json.SetAt($g(Msg),"msg")
    d json.SetAt($g(msgcode),"msgcode")
    d json.SetAt($g(Status),"status") 
    i $g(dialog)'="" {
        d json.SetAt($g(dialog),"dialog")
    }
    d json.SetAt($g(output),"output")  
    q ##class(Nur.MNISV3.Common.JSON).Encode(json)
errEditQuestionV4
    s Msg=$ze
    q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson(Msg,"100021","-1")
}

/// 护理计划详情
/// w ##class(Nur.MNISV3.Service.NursingPlan).GetPlanDetailV4("36||9","","","3","20665","8","2","23")
ClassMethod GetPlanDetailV4(id, motion, form, wardId, userId, locId, hospitalId, groupId) As %String
{
    n (id,motion,form,wardId, userId, locId, hospitalId,groupId,%session)
    s $zt="errGetPlanDetailV4"
    s ^GRS("GetPlanDetailV4")=$lb(id,motion,form,wardId, userId, locId, hospitalId,groupId)
    s Msg="成功",msgcode="999999",Status="0" //定义初始值
    s json=##class(%ArrayOfDataTypes).%New()
    s planId=$p(id,"||"),quesSub=$p(id,"||",2)
    s episodeId=..GetAdmIdByPlanId(id)
    s factorObj=##class(%ResultSet).%New("Nur.NIS.Service.NursingPlan.GoalInterventionRecord:QueryRelateFactorByQuestID")
    d factorObj.Execute(planId,quesSub)
    s factorData=##class(Nur.MNISV3.Common.Utils).ResultSetToList(factorObj)
    
    s goalObj=##class(%ResultSet).%New("Nur.NIS.Service.NursingPlan.GoalInterventionRecord:QueryGoalByQestID")
    d goalObj.Execute(planId,quesSub)
    s goalData=##class(Nur.MNISV3.Common.Utils).ResultSetToList(goalObj)
    
    s interventionObj=##class(%ResultSet).%New("Nur.NIS.Service.NursingPlan.GoalInterventionRecord:QueryInterventionByQestID")
    d interventionObj.Execute(planId,quesSub,"","Y",hospitalId)
    s interventionData=##class(%ListOfDataTypes).%New()
    while(interventionObj.Next()){
         s intervention=##class(Nur.MNISV3.Common.Utils).ResultSet(interventionObj)
         s intervId=interventionObj.GetDataByName("intervDR")
         s obj=##class(CF.NUR.NIS.Intervention).%OpenId(intervId)
         s typeId=obj.NIVTTypeDRGetObjectId()
         s intEnableDate=$zd(obj.NIVTEnableDate,3)
         s intStopDate=$zd(obj.NIVTStopDate,3)
         d obj.%Close()
         d intervention.SetAt(typeId,"intTypeID")
         d intervention.SetAt(intEnableDate,"intEnableDate")
         d intervention.SetAt(intStopDate,"intStopDate")
         d interventionData.Insert(intervention)
    }
    
    s interventionTypeObj=##class(%ResultSet).%New("Nur.NIS.Service.NursingPlan.InterventionSetting:FindInterventionType")
    d interventionTypeObj.Execute("",hospitalId)
    s interventionTypeItems=##class(Nur.MNISV3.Common.Utils).ResultSetToList(interventionTypeObj)

    s interventionFreqObj=##class(%ResultSet).%New("Nur.NIS.Service.NursingPlan.QuestionSetting:QueryInterventionFreq")
    d interventionFreqObj.Execute("","Y",hospitalId,$g(episodeId))
    s interventionFreqItems=##class(Nur.MNISV3.Common.Utils).ResultSetToList(interventionFreqObj)
    
    d json.SetAt($g(Msg),"msg")
    d json.SetAt($g(msgcode),"msgcode")
    d json.SetAt($g(Status),"status") 
    d json.SetAt($g(factorData),"factorData")  
    d json.SetAt($g(goalData),"goalData") 
    d json.SetAt($g(interventionData),"interventionData") 
    d json.SetAt($g(interventionTypeItems),"interventionTypeItems") 
    d json.SetAt($g(interventionFreqItems),"interventionFreqItems") 
    q ##class(Nur.MNISV3.Common.JSON).Encode(json)
errGetPlanDetailV4
    s Msg=$ze
    q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson(Msg,"100021","-1")
}

/// 查询护理问题可选项（在新增护理问题之前调用）
/// w ##class(Nur.MNISV3.Service.NursingPlan).GetQuestionItemsV4("36||9","","","3","20665","8","2","23")
ClassMethod GetQuestionItemsV4(episodeId, wardId, userId, locId, hospitalId, groupId) As %String
{
    n (episodeId,wardId, userId, locId, hospitalId,groupId,%session)
    s $zt="errGetQuestionItemsV4"
    s ^GRS("GetQuestionItemsV4")=$lb(episodeId,wardId, userId, locId, hospitalId,groupId)
    s Msg="成功",msgcode="999999",Status="0" //定义初始值
    s json=##class(%ArrayOfDataTypes).%New()
    ;;;items表示配置数据，type表示被配置指向的配置数据（不是名字叫type就是type），data表示业务数据
    s itemsObj=##class(%ResultSet).%New("Nur.NIS.Service.NursingPlan.QuestionRecord:GetQuestionList")
    d itemsObj.Execute(wardId,"","",episodeId,hospitalId)
    s questionItems=##class(Nur.MNISV3.Common.Utils).ResultSetToList(itemsObj)
    s typeItemsObj=##class(%ResultSet).%New("Nur.NIS.Service.NursingPlan.QuestionSetting:QueryQuestionType")
    d typeItemsObj.Execute("",hospitalId)
    s questionTypeItems=##class(Nur.MNISV3.Common.Utils).ResultSetToList(typeItemsObj)
    
    d json.SetAt($g(Msg),"msg")
    d json.SetAt($g(msgcode),"msgcode")
    d json.SetAt($g(Status),"status") 
    d json.SetAt($g(questionItems),"questionItems")  
    d json.SetAt($g(questionTypeItems),"questionTypeItems") 
    q ##class(Nur.MNISV3.Common.JSON).Encode(json)
errGetQuestionItemsV4
    s Msg=$ze
    q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson(Msg,"100021","-1")
}

/// 保存（现在叫做提交）非评估相关因素、护理目标和护理措施
/// w ##class(Nur.MNISV3.Service.NursingPlan).EditPlanDetailV4("36||9","submit","{""interventionData"":""[{\""startDatetime\"":\""\"",\""intervName\"":\""评估疼痛性质、程度、持续时间、伴随症状和体征、疼痛的原因，倾听患者对疼痛的诉说。\"",\""intervDR\"":\""52\"",\""defFreq\"":\""1\"",\""intTypeID\"":\""2\"",\""rowID\"":\""\""},{\""startDatetime\"":\""\"",\""intervName\"":\""解释原因，给予安慰及支持，鼓励说出内心感受。\"",\""intervDR\"":\""57\"",\""defFreq\"":\""1\"",\""intTypeID\"":\""4\"",\""rowID\"":\""\""}]""}","3","20665","8","2","23")
ClassMethod EditPlanDetailV4(id, motion, form, wardId, userId, locId, hospitalId, groupId) As %String
{
    n (id,motion,form,wardId, userId, locId, hospitalId,groupId,%session)
    s $zt="errEditPlanDetailV4"
    s ^GRS("EditPlanDetailV4")=$lb(id,motion,form,wardId, userId, locId, hospitalId,groupId)
    s Msg="成功",msgcode="999999",Status="0" //定义初始值
    s json=##class(%ArrayOfDataTypes).%New()
    s planId=$p(id,"||"),quesSub=$p(id,"||",2)
    s quesItemId=..GetQuestionIdByPlanId(id)
    s episodeId=..GetAdmIdByPlanId(id)
    s data=##class(Nur.MNISV3.Common.JSON).Decode(form)
    if (motion="submit") { ;;;提交
        s factorData=data.GetAt("factorData")
        i (factorData'="") {
            s ids=##class(%ListOfDataTypes).%New()
            f ind=1:1:factorData.Count() {
                s factor=factorData.GetAt(ind)
                s detailId=factor.GetAt("factorDR")
                d ids.Insert(detailId)
            }
            s ret=##class(Nur.NIS.Service.NursingPlan.GoalInterventionRecord).CommitFactorRecord(planId,quesSub,userId,locId,wardId,ids)
            s err=ret.GetAt("errcode")
            i (err'=0) s Status="-1",Msg=err
        }
        s goalData=data.GetAt("goalData")
        i (goalData'="") {
            i '$isobject(goalData) s goalData=##class(Nur.MNISV3.Common.JSON).Decode(goalData)
            s ids=##class(%ListOfDataTypes).%New()
            f ind=1:1:goalData.Count() {
                s factor=goalData.GetAt(ind)
                s detailId=factor.GetAt("goalDR")
                d ids.Insert(detailId)
            }
            s ids=##class(Nur.MNISV3.Common.JSON).Encode(ids)
            s ret=##class(Nur.NIS.Service.NursingPlan.GoalInterventionRecord).SaveGoalRecord(planId,quesSub,userId,locId,wardId,ids)
            s err=ret.GetAt("errcode")
            i (err'=0) s Status="-1",Msg=err
        }
        s interventionData=data.GetAt("interventionData")
        i (interventionData'="") {
            i '$isobject(interventionData) s interventionData=##class(Nur.MNISV3.Common.JSON).Decode(interventionData)
            s ids=##class(%ListOfDataTypes).%New()
            f ind=1:1:interventionData.Count() {
                s factor=interventionData.GetAt(ind)
                s intervDR=factor.GetAt("intervDR")
                s freq=factor.GetAt("defFreq")
                s rowID=factor.GetAt("rowID")
                s detail=##class(Nur.Tools).RapidAssembly("intervdr^freqdr^rowID^startDateTime^week",intervDR,freq,rowID,"","")
                d ids.Insert(detail)
            }
            s ids=##class(Nur.MNISV3.Common.JSON).Encode(ids)
            s ret=##class(Nur.NIS.Service.NursingPlan.GoalInterventionRecord).SaveIntervRecord(planId,quesSub,userId,locId,wardId,"Y",ids,"N")
            s err=ret.GetAt("errcode")
            i (err'=0) s Status="-1",Msg=err
        }
    }
    i (motion="save") { ;;;新增
        s factorData=data.GetAt("factorData")
        i (factorData'="") {
            f ind=1:1:factorData.Count() {
                s factor=factorData.GetAt(ind)
                s detailId=factor.GetAt("factorDR")
                s name=factor.GetAt("factorName")
                s ret=##class(Nur.NIS.Service.NursingPlan.GoalInterventionRecord).AddFactorRecord(detailId,quesItemId,name,userId,locId,episodeId)
                i (ret'=0) s Status="-1",Msg=ret
            }
        }
        s goalData=data.GetAt("goalData")
        i (goalData'="") {
            i '$isobject(goalData) s goalData=##class(Nur.MNISV3.Common.JSON).Decode(goalData)
            f ind=1:1:goalData.Count() {
                s goal=goalData.GetAt(ind)
                s detailId=goal.GetAt("goalDR")
                s name=goal.GetAt("goalName")
                s ret=##class(Nur.NIS.Service.NursingPlan.GoalInterventionRecord).AddGoalRecordManual( planId,quesSub, userId,locId,wardId, name,quesItemId,detailId,episodeId)
                i (ret'=0)&&(ret'>0) s Status="-1",Msg=ret
            }
        }
        s interventionData=data.GetAt("interventionData")
        i (interventionData'="") {
            i '$isobject(interventionData) s interventionData=##class(Nur.MNISV3.Common.JSON).Decode(interventionData)
            f ind=1:1:interventionData.Count() {
                s intervention=interventionData.GetAt(ind)
                s detailId=intervention.GetAt("intervDR")
                s name=intervention.GetAt("intervName")
                s freq=intervention.GetAt("defFreq")
                s itemId=intervention.GetAt("intTypeID")
                s fromDate=intervention.GetAt("intEnableDate")
                s toDate=intervention.GetAt("intStopDate")
                s ret=##class(Nur.NIS.Service.NursingPlan.GoalInterventionRecord).SaveNewInterventionList(
                    userId,locId,wardId,itemId,name,name,fromDate,toDate,freq,"",quesItemId,episodeId,"",hospitalId,"" )
                i (ret'=0) s Status="-1",Msg=ret
            }
        }
    }
    d json.SetAt($g(Msg),"msg")
    d json.SetAt($g(msgcode),"msgcode")
    d json.SetAt($g(Status),"status") 
    q ##class(Nur.MNISV3.Common.JSON).Encode(json)
errEditPlanDetailV4
    s Msg=$ze
    q ##class(Nur.MNISV3.Common.Utils).ReturnMsgJson(Msg,"100021","-1")
}

/// 创建一个Dialog
/// w ##class(Nur.JSON).Encode(##class(Nur.MNISV3.Service.NursingPlan).CreateDialog("提示","是否复制该护理问题?","确定","copy","取消","outcome"))
ClassMethod CreateDialog(mTitle = "提示", message = "", okText = "确定", okBehavior = "", cancelText = "取消", cancelBehavior = "cancel")
{
    n (mTitle,message,okText,okBehavior,cancelText,cancelBehavior)
    s title=##class(Nur.Tools).RapidAssembly("text,backgroundColor",mTitle,"") 
    s message=##class(Nur.Tools).RapidAssembly("text,backgroundColor",message) 
    s buttons=##class(%ListOfDataTypes).%New() 
    // String request; CallbackBean callback;String motion; String autoClickTimeout; String autoHideOnClick;
    d buttons.Insert(##class(Nur.Tools).RapidAssembly("text,behavior,backgroundColor,color,disabled",okText,okBehavior))
    d buttons.Insert(##class(Nur.Tools).RapidAssembly("text,behavior,backgroundColor,color,disabled",cancelText,cancelBehavior))
   
    s dialog=##class(%ArrayOfDataTypes).%New()
    d dialog.SetAt($g(message),"message") //MessageBean
    d dialog.SetAt($g(title),"title") //TitleBean
    d dialog.SetAt($g(buttons),"buttons") //List<ButtonsBean>
    q dialog
}

ClassMethod GetQuestionName(quesItemId) As %String
{
    n (quesItemId)
    s obj=##class(CF.NUR.NIS.Question).%OpenId(quesItemId)
    q:('$isobject(obj)) ""
    s name=obj.NQShortNameCN
    d obj.%Close()
    q name
}

ClassMethod GetAdmIdByPlanId(id) As %String
{
    n (id)
    s planId=$p(id,"||")
    s obj=##class(Nur.NIS.PlanRecord).%OpenId(planId)
    q:('$isobject(obj)) ""
    s admId=$s($isobject(obj.NPRECAdmDR):obj.NPRECAdmDR.%Id(),1:"")
    d obj.%Close()
    q admId
}

ClassMethod GetQuestionIdByPlanId(id) As %String
{
    n (id)
    s obj=##class(Nur.NIS.QuestionRecord).%OpenId(id)
    q:('$isobject(obj)) ""
    s quesItemId=$s($isobject(obj.NQRECQuestionDR):obj.NQRECQuestionDR.%Id(),1:"")
    d obj.%Close()
    q quesItemId
}

ClassMethod GetQuestionDataObj(episodeId, fromDate, toDate, wardId, userId, locId, hospitalId, groupId, screenParts) As %String
{
    n (episodeId,fromDate,toDate, wardId, userId, locId, hospitalId,groupId,screenParts,%session)
    s data=##class(%ListOfDataTypes).%New()
    s fromDate=##class(websys.Conversions).DateHtmlToLogical(fromDate)
    s toDate=##class(websys.Conversions).DateHtmlToLogical(toDate)
    k temp
    w screenParts,!
    d ##class(Nur.Tools).ExtractFilterStr(screenParts,.temp) 
    // 问题评价状态(0：未评价 1：已评价) Property NQREC QStatus  
    s eStatus=$g(temp("eStatus")),qStatus=$g(temp("qStatus")),source=$g(temp("source"))
    s stauts=$s(eStatus="未评价":0,eStatus="已评价":1,1:"")
    // 状态（0：未停止 1：已停止 2：已撤销 3：已作废）  Property NQREC Status 
    s qStatus=$s(qStatus="未停止":0,qStatus="已停止":1,qStatus="已撤销":2,qStatus="已作废":3,1:"")
    // 问题来源（0:评估带入 1:手动添加 2:数值代入 3:复制 4:医嘱带入 5:诊断带入） 需求号2588619 数据来源名称：数值代入应改为数值带入  Property NQRECSourc
    s source=$s(source="评估带入":0,source="手动添加":1,source="数值代入":2,source="复制":3,source="医嘱带入":4,source="诊断带入":5,1:"")
    s resultObj=##class(%ResultSet).%New("Nur.NIS.Service.NursingPlan.QuestionRecord:GetPatientQuestionList")
    d resultObj.Execute(episodeId,fromDate,toDate,$g(stauts),"",$g(qStatus),$g(source))
    while(resultObj.Next()){
         s res=##class(Nur.MNISV3.Common.Utils).ResultSet(resultObj)
         s statusName=resultObj.GetDataByName("statusName")
         s buttons=##class(%ListOfDataTypes).%New()
         i statusName="已停止" {
             d buttons.Insert("QuestionUnUse") //可"作废"
             d buttons.Insert("CopyQuestion") //可"复制"
         }
         i statusName="已作废" {
             d buttons.Insert("CopyQuestion") //可"复制"
         }
         i statusName="未停止" {
             d buttons.Insert("QuestionStop") //可"停止" 
             d buttons.Insert("QuestionUnUse") //可"作废"
         }
         d res.SetAt(buttons,"buttons")
         d data.Insert(res)
    }
    q data
}

ClassMethod AddScreenPartObject(commonKey, keyCode, keyDesc, keyType, keyValue)
{
    s obj=##class(%ArrayOfDataTypes).%New()
    d obj.SetAt($g(commonKey),"commonKey")
    d obj.SetAt($g(keyCode),"keyCode")
    d obj.SetAt($g(keyDesc),"keyDesc")
    d obj.SetAt($g(keyType),"keyType")
    d obj.SetAt($g(keyValue),"keyValue")
    q obj
}

}
